home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / timecodes / qttimecode / common files / macframework.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  9.5 KB  |  328 lines

  1. //
  2. //    File:        MacFramework.h
  3. //
  4. //    Contains:    Basic functions for windows, menus, and similar things.
  5. //
  6. //    Written by:    Tim Monroe
  7. //                Based on the MovieShell code written by Apple DTS.
  8. //
  9. //    Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //    Change History (most recent first):
  12. //
  13. //       <6>         11/02/98    rtm        minor reworking to coordinate with WinFramework.h
  14. //       <5>         11/07/97    rtm        revised syntax of DoApplicationEventLoopAction
  15. //       <4>         02/26/97    rtm        added fCanEditMovie field to WindowObjectRecord
  16. //       <3>         12/05/96    rtm        added fMovie and fInstance to WindowObjectRecord
  17. //       <2>         11/27/96    rtm        conversion to personal coding style
  18. //       <1>         12/20/94    khs        first file
  19. //       
  20.  
  21. #pragma once
  22.  
  23. // header files
  24.  
  25. #ifndef __APPLEEVENTS__
  26. #include <AppleEvents.h>
  27. #endif
  28.  
  29. #ifndef __DEVICES__
  30. #include <Devices.h>
  31. #endif
  32.  
  33. #ifndef __DIALOGS__
  34. #include <Dialogs.h>
  35. #endif
  36.  
  37. #ifndef __DISKINIT__
  38. #include <DiskInit.h>
  39. #endif
  40.  
  41. #ifndef __FIXMATH__
  42. #include <FixMath.h>
  43. #endif
  44.  
  45. #ifndef __FONTS__
  46. #include <Fonts.h>
  47. #endif
  48.  
  49. #ifndef __MACMEMORY__
  50. #include <MacMemory.h>
  51. #endif
  52.  
  53. #ifndef __MENUS__
  54. #include <Menus.h>
  55. #endif
  56.  
  57. #ifndef __MOVIES__
  58. #include <Movies.h>
  59. #endif
  60.  
  61. #ifndef __PROCESSES__
  62. #include <Processes.h>
  63. #endif
  64.  
  65. #ifndef __QUICKTIMECOMPONENTS__
  66. #include <QuickTimeComponents.h>
  67. #endif
  68.  
  69. #ifndef __QUICKTIMEVR__
  70. #include <QuickTimeVR.h>
  71. #endif
  72.  
  73. #ifndef __RESOURCES__
  74. #include <Resources.h>
  75. #endif
  76.  
  77. #ifndef __SEGLOAD__
  78. #include <SegLoad.h>
  79. #endif
  80.  
  81. #ifndef __SOUND__
  82. #include <Sound.h>
  83. #endif
  84.  
  85. #ifndef __TEXTUTILS__
  86. #include <TextUtils.h>
  87. #endif
  88.  
  89. #ifndef __TOOLUTILS__
  90. #include <ToolUtils.h>
  91. #endif
  92.  
  93. #ifndef __TRAPS__
  94. #include <Traps.h>
  95. #endif
  96.  
  97. #ifndef __QTUtilities__
  98. #include "QTUtilities.h"
  99. #endif
  100.  
  101. #include <stdio.h>
  102. #include <string.h>
  103.  
  104.  
  105. //////////
  106. //
  107. // constants
  108. //
  109. //////////
  110.  
  111. #define kEmergencyMemorySize        40*1024L        // size of the block of memory used for our grow zone procedure
  112. #define kExtraStackSpaceSize        32*1024L        // amount of additional stack space
  113.  
  114. #define kBroughtToFront                3                // number of times to call EventAvail at application startup
  115.  
  116. #define kNewMovieName                "untitled.mov"    // default name of a movie created by "New" menu command
  117.  
  118. #define kInvalidFileRefNum            -1                // an invalid file reference number
  119.  
  120. enum {
  121.     kMovieControllerObject          = FOUR_CHAR_CODE('MCvr')
  122. };
  123.  
  124. // for menus
  125. enum eMenubar { 
  126.     mMenubar        = 128
  127. };
  128.  
  129. enum eMainMenus {
  130.     mApple            = 128,
  131.     mFile,
  132.     mEdit
  133. };
  134.  
  135. enum  eAppleMenu {
  136.     iAbout            = 1
  137. };
  138.  
  139. enum eFileMenu {
  140.     iNew            = 1,
  141.     iOpen,
  142.     iClose,
  143.     iSave,
  144.     iSaveAs,
  145.     iPrint            = 7,
  146.     iQuit            = 9
  147. };
  148.  
  149. enum eEditMenu {
  150.     iUndo            = 1,
  151.     iCut            = 3,
  152.     iCopy,
  153.     iPaste,
  154.     iClear,
  155.     iSelectAll        = 8,
  156.     iPreferences    = 10
  157. };
  158.  
  159. // for dialogs
  160. enum eDialogs {
  161.     kAboutBoxID                        = 128,                    // dialog ID for About box
  162.     kAlertErrorID                    = 129,                    // dialog ID for warning box
  163.     kSaveDialogID                    = 130                    // dialog ID for "Save changes..." dialog box
  164. };
  165.  
  166. // items in these dialogs
  167. #define kSaveChanges                1                        // save the changes before closing window
  168. #define kCancelClose                2                        // no, don't close the window or save changes
  169. #define kDontSaveChanges            3                        // discard any unsaved changes
  170.  
  171.  
  172. #define kOKButtonUserItem            4
  173.  
  174. // constants for standard modal dialog filter proc
  175. #define kMyButtonDelay                8
  176. #define kReturnKey                    (char)0x0D    
  177. #define kEnterKey                    (char)0x03    
  178. #define kEscapeKey                    (char)0x1B    
  179. #define kPeriod                        '.'
  180.  
  181. // constants for selecting InitApplication phase
  182. enum {
  183.     kInitAppPhase_BeforeCreateFrameWindow     = 1L << 0,        // MDI frame window windows not yet created
  184.     kInitAppPhase_AfterCreateFrameWindow    = 1L << 1,        // MDI frame window windows already created
  185.     kInitAppPhase_BothPhases                = kInitAppPhase_BeforeCreateFrameWindow | kInitAppPhase_AfterCreateFrameWindow
  186. };
  187.  
  188. // constants for selecting StopApplication phase
  189. enum {
  190.     kStopAppPhase_BeforeDestroyWindows         = 1L << 0,        // movie windows not yet torn down
  191.     kStopAppPhase_AfterDestroyWindows        = 1L << 1,        // movie windows already torn down
  192.     kStopAppPhase_BothPhases                = kStopAppPhase_BeforeDestroyWindows | kStopAppPhase_AfterDestroyWindows
  193. };
  194.  
  195. // parameters to the SetMenuItemState function
  196. #define kEnableMenuItem                0x00000000L
  197. #define kDisableMenuItem            0x00000001L
  198.  
  199. // resource ID for string resource containing application's name
  200. #define kAppNameResID                1000
  201. #define kAppNameResIndex            1
  202.  
  203. #define kDefaultWindowTitle            "\puntitled"
  204.  
  205.  
  206. /////////
  207. //
  208. // macros
  209. //
  210. //////////
  211.  
  212. // macros for converting Mac menu ID/menu item pairs into a single "menu item identifier"
  213. #define MENU_IDENTIFIER(menuID,menuItem)    ((menuID<<8)+(menuItem))
  214. #define MENU_ID(menuIdentifier)                ((menuIdentifier&0xff00)>>8)
  215. #define MENU_ITEM(menuIdentifier)            ((menuIdentifier&0x00ff))
  216.  
  217.  
  218. //////////
  219. //
  220. // data types
  221. //
  222. //////////
  223.  
  224. typedef MenuHandle            MenuReference;
  225. typedef WindowRef            WindowReference;
  226. typedef short                WORD;
  227.  
  228.  
  229. //////////
  230. //
  231. // structures
  232. //
  233. //////////
  234.  
  235. // WindowObjectRecord is a data structure attached to a movie window.
  236. // We use this structure to associate data with any window presented.
  237.  
  238. typedef struct {
  239.     WindowReference            fWindow;            // the window
  240.     OSType                    fObjectType;        // specific tag indicating that the window object belongs to our application
  241.     Movie                    fMovie;                // the main movie (QT or QTVR)
  242.     MovieController         fController;        // the movie controller for this window
  243.     FSSpec                    fFileFSSpec;        // location of the movie file
  244.     short                    fFileResID;
  245.     short                    fFileRefNum;
  246.     Boolean                    fCanResizeWindow;    // can the window be resized?
  247.     Boolean                    fDirty;                // has the movie data changed since the last save?
  248.     QTVRInstance            fInstance;            // the QTVRInstance
  249.     Handle                    fAppData;            // a handle to application-specific window data
  250. } WindowObjectRecord, *WindowObjectPtr, **WindowObject;
  251.  
  252.  
  253. //////////
  254. //
  255. // function prototypes
  256. //       
  257. //////////
  258.  
  259. void                        InitStack (long extraStackSpace);
  260. void                         InitMacEnvironment (long nMoreMasters);
  261. pascal long                    AppGrowZoneCallback (Size theBytesNeeded);
  262. Boolean                     InitMenubar (void);
  263. void                         MainEventLoop (void);
  264. void                         HandleMenuCommand (long theMenuResult);
  265. void                         AdjustMenus (void);
  266. void                         HandleKeyPress (EventRecord *theEvent);
  267. void                        QuitFramework (void);
  268.  
  269. Boolean                     DoCreateNewMovie (void);
  270. MovieController                SetupMovieWindowWithController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow);
  271. Boolean                     DoCreateMovieWindow (Movie theMovie, FSSpec *theFSSpec);
  272. void                         DoDestroyMovieWindow (WindowReference theWindow);
  273. OSErr                        DoSaveAsMovieFile (WindowReference theWindow);
  274. Boolean                     DoUpdateMovieFile (WindowReference theWindow);
  275. void                         DoActivateWindow (WindowReference theWindow, Boolean becomingActive);
  276. PASCAL_RTN void                StandardUserItemProcedure (DialogPtr theDialog, short theItem);
  277. PASCAL_RTN Boolean            StandardModalDialogEventFilter (DialogPtr theDialog, EventRecord *theEvent, short *theItemHit);
  278. Boolean                        CheckMovieControllers (EventRecord *theEvent);
  279.  
  280. Boolean                     IsAppWindow (WindowReference theWindow);
  281. Boolean                        IsDocWindow (WindowReference theWindow);
  282. WindowObject                 CreateWindowObject (WindowReference theWindow);
  283.  
  284. void                        SizeWindowToMovie (WindowObject theWindowObject);
  285. void                         ShowAboutBox (void);
  286. void                         ShowWarning (Str255 theMessage, OSErr theErr);
  287.  
  288. WindowReference                GetFrontMovieWindow (void);
  289. WindowReference                GetNextMovieWindow (WindowReference theWindow);
  290. WindowObject                GetWindowObjectFromFrontWindow (void);
  291. WindowObject                GetWindowObjectFromWindow (WindowReference theWindow);
  292. MovieController              GetMCFromFrontWindow (void);
  293. MovieController                GetMCFromWindow (WindowReference theWindow);
  294. QTVRInstance                GetQTVRInstanceFromFrontWindow (void);
  295. Handle                        GetAppDataFromFrontWindow (void);
  296. Handle                        GetAppDataFromWindow (WindowReference theWindow);
  297. Handle                        GetAppDataFromWindowObject (WindowObject theWindowObject);
  298. Boolean                     IsWindowObjectOurs (WindowObject theObject);
  299. void                        DoBeep (void);
  300. void                        SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  301. void                        SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  302. void                        SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText);
  303. void                        SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState);
  304. GrafPtr                        GetPortFromWindowReference (WindowReference theWindow);
  305. WindowReference                GetWindowReferenceFromPort (GrafPtr thePort);
  306. short                        GetWindowWidth (WindowReference theWindow);
  307. WindowReference                GetFrontAppWindow (void);
  308. WindowReference                GetNextAppWindow (WindowReference theWindow);
  309.  
  310.  
  311. // application-specific functions
  312. // These are defined in the ComApplication.c file;
  313. // you could override these to change the behavior of the function in a specific application.
  314. void                        InitApplication (UInt32 theStartPhase);
  315. void                        StopApplication (UInt32 theStopPhase);
  316. void                        DoIdle (WindowReference theWindow);
  317. void                        DoUpdateWindow (WindowReference theWindow, Rect *theRefrehArea);
  318. void                         HandleContentClick (WindowReference theWindow, EventRecord *theEvent);
  319. Boolean                        HandleApplicationKeyPress (char theCharCode);
  320. WindowRef                     CreateMovieWindow (Rect *theRect, Str255 theTitle);
  321. void                         HandleApplicationMenu (UInt16 theMenuItem);
  322. void                        AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu);
  323. Boolean                        DoApplicationEventLoopAction (EventRecord *theEvent);
  324. void                        AddControllerFunctionality (MovieController theMC);
  325. void                        InitApplicationWindowObject (WindowObject theWindowObject);
  326. void                        RemoveApplicationWindowObject (WindowObject theWindowObject);
  327. PASCAL_RTN Boolean            ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon);
  328.